import request from "@/utils/request";
import {QueueRegCategoryModel} from "@/model/QueueRegCategoryModel";

export default class RegCategoryApi {
    /**
     * 查询类目列表
     *
     */
    public static listRegCategory(): Promise<QueueRegCategoryModel[]> {
        return new Promise((resolve, reject) => {
            request({
                url: '/queue/reg_category/list',
                method: 'get',
            }).then((res: any) => {
                if (res.code === 200) {
                    resolve(res.data.map(item => new QueueRegCategoryModel().deserialize(item)))
                } else {
                    reject(res)
                }
            }, ()=> {reject()})
        })
    }

    public static saveRegCategory(categoryModel: QueueRegCategoryModel): Promise<QueueRegCategoryModel> {
        return new Promise((resolve, reject) => {
            request({
                url: '/queue/reg_category/save',
                method: 'POST',
                data: categoryModel
            }).then((res: any) => {
                if (res.code === 200) {
                    resolve(new QueueRegCategoryModel().deserialize(res.data))
                } else {
                    reject(res)
                }
            }, ()=> {reject()})
        })
    }

    public static updateRegCategory(id: string, categoryModel: QueueRegCategoryModel): Promise<boolean> {
        return new Promise((resolve, reject) => {
            request({
                url: `/queue/reg_category/${id}`,
                method: 'PUT',
                data: categoryModel
            }).then((res: any) => {
                if (res.code === 200) {
                    resolve(true)
                } else {
                    reject()
                }
            }, ()=> {reject()})
        })
    }

    public static deleteRegCategory(id: string): Promise<boolean> {
        return new Promise((resolve, reject) => {
            request({
                url: `/queue/reg_category/${id}`,
                method: 'DELETE'
            }).then((res: any) => {
                if (res.code === 200) {
                    resolve(true)
                } else {
                    reject()
                }
            }, ()=> {reject()})
        })
    }
}